package demo2;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-11
 * Time: 16:53
 */
public class TestDemo6 {

    public static void main(String[] args) {
        //创建一个抢占式执行的线程池---任务执行顺序不确定
        ExecutorService threadPool = Executors.newWorkStealingPool();
        for(int i =0;i<10;++i){
            int index = i;
            threadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(index + "任务执行");
                }
            });
        }
        //确保任务执行完毕
        while(!threadPool.isTerminated()){

        }
    }

}
